package com.itheima.goods.controller;

import com.itheima.goods.pojo.Goods;
import com.itheima.goods.service.GoodsService;
import entity.PageResult;
import entity.QueryPageBean;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")

public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/search/{page}/{size}")
    public Result search(@PathVariable("page") Integer page,@PathVariable("size") Integer size) {
        return goodsService.findPage(page, size,null);
    }
    @PostMapping("/search/{page}/{size}")
    public Result searchMap(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody Object searchMap) {
        return goodsService.findPage(page, size,searchMap);
    }
    @GetMapping("/findAll")
    public Result findAll() {

        return goodsService.findAll();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        return this.goodsService.findById(id);
    }

    @PostMapping
    public Result add(@RequestBody Goods goods) {

        return this.goodsService.add(goods);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {

        return  goodsService.delete(id);
    }
    @PutMapping("/{id}")
    public Result updated(@PathVariable Integer id,@RequestBody Goods goods) {

        return  goodsService.updateGoods(id,goods);
    }

    @PutMapping("/up/{id}")
    public Result upGoods(@PathVariable Integer id) {

        return this.goodsService.upGoods(id);
    }

    @PutMapping("/down/{id}")
    public Result downGoods(@PathVariable Integer id) {

        return   this.goodsService.downGoods(id);
    }

    @PutMapping("/status/{id}/{status}")
    public Result updateStatus(@PathVariable Integer id, @PathVariable String status) {

        return  this.goodsService.updateStatus(id, status);
    }


}
